package cs342.uwosh.edu.MyWorldApp.storage;

import android.os.Parcel;
import android.os.Parcelable;

// TODO Needs to be discussed

public class Location implements Parcelable
{
	public static final String STEALTHED = null;
	public static final int PARCEL_DESCRIPTION = 1;
	
	public static final Parcelable.Creator<Location> CREATOR = new Parcelable.Creator<Location>() {
		public Location createFromParcel(Parcel in) {     
			return new Location(in);
		}
		
		public Location[] newArray(int size) {
		    return new Location[size];
		}
	};
	
	// Should these be doubles or integers?
	private int latitude;
	private int longitude;
	
	public Location(Parcel in) {
		latitude = in.readInt();
		longitude = in.readInt();
	}
	
	public Location(String location) {
		String[] coordinates = location.split("/");
		latitude = Integer.parseInt(coordinates[0]);
		longitude = Integer.parseInt(coordinates[1]);
	}
	
	public Location(int latitude, int longitude) {
		update(latitude, longitude);
	}
	
	public void update(int latitude, int longitude) {
		this.latitude = latitude;
		this.longitude = longitude;
	}
	
	public double getLatitude() {
		return ((double)latitude / 1E6);
	}
	
	public double getLongitude() {
		return ((double)longitude / 1E6);
	}
	
	public String[] toStringArray() {
		return new String[]{"" + (latitude / 1E6), "" + (longitude / 1E6), ""};
	}
	
	public String toString() {
		return latitude + "/" + longitude;
	}

	public int describeContents() {
		return PARCEL_DESCRIPTION;
	}

	public void writeToParcel(Parcel out, int flags) {
		out.writeInt(latitude);
		out.writeInt(longitude);
	}
}